﻿using VisualWip.Core.Interfaces;

namespace VisualWip.Core.Columns
{
    public class SingleWorkItemColumn : WorkItemsColumnBase
    {
        private WorkItem _workItem;

        private string _workItemId;

        public SingleWorkItemColumn(IWorkItemProviderFactory workItemProviderFactory)
            : base(workItemProviderFactory)
        {
            Height = 200;
            Width = 300;
            PositionY = 0;
            ColumnType = ColumnType.Other;
            WorkItemSize = WorkItemSize.Large;
        }

        public string WorkItemId
        {
            get { return _workItemId; }
            set
            {
                if (value != _workItemId)
                {
                    _workItemId = value;
                    OnPropertyChanged(this, () => WorkItemId);
                }
            }
        }

        public WorkItem WorkItem
        {
            get { return _workItem; }
            set
            {
                if (value != _workItem)
                {
                    _workItem = value;
                    OnPropertyChanged(this, () => WorkItem);
                }
            }
        }

        public override PersistenceTree Persist(string name)
        {
            PersistenceTree settings = base.Persist(name);
            settings.Add(() => WorkItemId);
            return settings;
        }

        public override void Load(PersistenceTree settings)
        {
            base.Load(settings);
            WorkItemId = settings.Get(() => WorkItemId,string.Empty);
        }


        public override void DoRefresh()
        {
            WorkItem = WorkItemProvider.GetWorkItem(WorkItemId);
        }
    }
}